<cfquery name="qryecindtrupdatepx" datasource="#client.company_dsn#">
	select referencedate
	from ecindtrupdatepx
	where docnumber = '#thedocnumber#'
	and referencedate = '#evaluate("form.edtreferencedate#form.selseqno#")#'
</cfquery>
<cfif not qryecindtrupdatepx.recordcount>
	<cftry>
	<cfquery name="insertnew" datasource="#client.company_dsn#">
		insert into ecindtrupdatepx (docnumber,sequenceno,pid,referencedate,datein,[in],dateout,out,remarks,reccreatedby,recdatecreated)	values('#thedocnumber#','#form.selseqno#','#pid#','#evaluate("form.edtreferencedate#form.selseqno#")#','#evaluate("form.edtdatein#form.selseqno#")#','#evaluate("form.edtin#form.selseqno#")#','#evaluate("form.edtdateout#form.selseqno#")#','#evaluate("form.edtout#form.selseqno#")#','#evaluate("form.edtremarks#form.selseqno#")#','#client.userid#',#now()#)
	</cfquery>
	<cfset session.themessage = "Record was successfully saved.">
	<cfcatch>
		<cfset sesson.themessage = "Record was not saved successfully." &"<br>" &cfcatch.Message &"<br>" &cfcatch.Message>
	</cfcatch>
	</cftry>
<cfelse>
	<cftransaction>
	<cftry>
	<cfquery name="delexisting" datasource="#client.company_dsn#">
		delete from ecindtrupdatepx
		where docnumber = '#thedocnumber#'
			and pid = '#pid#'
			and referencedate = '#evaluate("form.edtreferencedate#form.selseqno#")#'
	</cfquery>
	<cfquery name="insertnew" datasource="#client.company_dsn#">
		insert into ecindtrupdatepx (docnumber,sequenceno,pid,referencedate,datein,[in],dateout,out,remarks,reccreatedby,recdatecreated)
		values('#thedocnumber#','#form.selseqno#','#pid#','#evaluate("form.edtreferencedate#form.selseqno#")#','#evaluate("form.edtdatein#form.selseqno#")#','#evaluate("form.edtin#form.selseqno#")#','#evaluate("form.edtdateout#form.selseqno#")#','#evaluate("form.edtout#form.selseqno#")#','#evaluate("form.edtremarks#form.selseqno#")#','#client.userid#',#now()#)
	</cfquery>
	<cfset session.themessage = "Record was successfully saved.">
	<cfcatch>
		<cftransaction action="rollback">
		<cfset sesson.themessage = "Record was not saved successfully." &"<br>" &cfcatch.Message &"<br>" &cfcatch.Message>
	</cfcatch>
	</cftry>
	</cftransaction>
</cfif>